function Imap(Y,R,num1,num2,options,labels,lim,data) 

dims = options.dims; 
comp = options.comp; 
overlay = options.overlay; 
displ = options.display; 
verbose = options.verbose; 

%%%%%%%%%%%%%%%%%% Graphics %%%%%%%%%%%%%%%%%%

if (displ==1)
     %%%%% Plot fall-off of residual variance with dimensionality %%%%%
     figure;
     hold on
     plot(dims, R, 'bo'); 
     plot(dims, R, 'b-'); 
     hold off
     ylabel('Residual variance'); 
     xlabel('Isomap dimensionality'); 

     %%%%% Plot two-dimensional configuration %%%%%
     twod = find(dims==2); 
     if ~isempty(twod)
         figure;
         hold on;
         for i=1:lim
             if labels(1,i)==num1 
                 if(mod(i, 40)==0)
                    img = reshape(data(:,i), 28, 28);
                    img = img';
                    RgbImage = repmat(uint8(255.*img), [1 1 3]);
                    imagesc([Y.coords{twod}(1,i)+0.5 Y.coords{twod}(1,i)+5*power(10,2)], [Y.coords{twod}(2,i)+5*power(10, 2) Y.coords{twod}(2,i)+0.5], RgbImage);
                 end
                plot(Y.coords{twod}(1,i), Y.coords{twod}(2,i), 'ro'); 
             end
             if labels(1,i)==num2
                 if(mod(i, 40)==0)
                    img = reshape(data(:,i), 28, 28);
                    img = img';
                    RgbImage = repmat(uint8(255.*img), [1 1 3]);
                    imagesc([Y.coords{twod}(1,i)+0.5 Y.coords{twod}(1,i)+5*power(10,2)], [Y.coords{twod}(2,i)+5*power(10, 2) Y.coords{twod}(2,i)+0.5], RgbImage);
                 end
                 plot(Y.coords{twod}(1,i), Y.coords{twod}(2,i), 'bo');
             end
         end
         if num1==1 && num2==7
             legend('1','7');
         end
         if(num1==4 && num2==9)
             legend('4','9');
         end
         if (overlay == 1)
             %gplot(E(Y.index, Y.index), [Y.coords{twod}(1,:); Y.coords{twod}(2,:)]'); 
             title('Two-dimensional Isomap embedding (with neighborhood graph).'); 
         else
             title('Two-dimensional Isomap.'); 
         end
         hold off;
     end
end
return;